<?php
load_ctl("Common");
class PhotoController extends CommonController
{ 
	function init(){
		parent::init();
		load_model('Class');
		$this->class = new APclass();
		load_model('Photo');
		$this->pho = new Photo();
    }
	public function indexAction(){
		if(isset($_GET["cid"])){
			$cid = intval($_GET["cid"]);
		}else{
			$this->_redirect('/');
		}
		$page = isset($_GET["p"]) ? intval($_GET["p"]) : 1;
	    $page < 1 && $page = 1;
		$page_size = 5;
		$class_info = $this->class->get_class_info($cid);
		$this->view->class_name = $class_info["class_name"];
		
		$this->view->webTitle = $class_info["class_name"].' - ';
		$this->view->keywords = $class_info["class_name"];
		$this->view->description = $class_info["class_name"];
		//左边推荐相册
		$fid = $this->class->get_class_fid($cid);
		$this->view->pho_lists = $this->class->get_pholists($fid);
		$this->view->photos = $this->pho->get_phoclass_info($cid);
		//取相册评论
		load_model("Comment");
		$comment = new Comment();
		$this->view->class_comment = $comment->get_comment_by_class_pho($cid);
		$this->view->total_comment = count($this->view->class_comment);
		$paginator = Zend_Paginator::factory($this->view->class_comment); 
		$paginator->setCurrentPageNumber($page);
		$paginator->setItemCountPerPage($page_size); 
		$this->view->paginator = $paginator;
		
		echo $this->view->render('photo.phtml');        
	}
	
	public function addcomAction(){
		if($this->_request->isPost()){
			$cid = $this->_request->getPost('cid');
			$filter = new Zend_Filter_StripTags();
			if(trim($this->_request->getPost('com_writer')) == ''){
				php_alert("用户名不能为空",-1);
				exit;
			}elseif(trim($this->_request->getPost('com_content')) == ''){
				php_alert("内容不能为空",-1);
				exit;
			}else{
				php_alert("相册已经禁止评论谢谢",-1);
				exit;
			}
			$data = array(
				'com_art_id'=>null,
				'com_pho_id'=>$cid,
				'com_writer'=>$filter->filter($this->_request->getPost('com_writer')),
				'com_content'=>$filter->filter($this->_request->getPost('com_content')),
				'com_date'=>time()
			);
			load_model("Comment");
			$comment = new Comment();
			$comment->add_comment($data);
			php_alert("评论发表成功",-1);
			
		}else{
			$this->_redirect("/");
		}
	}
	public function noRouteAction(){
		$this->_redirect('/');
	}
}
?>